package com.ruan.service;

import com.ruan.dao.CommentsMapper;
import com.ruan.dao.CommentsTypeMapper;
import com.ruan.entity.Comments;
import com.ruan.entity.Result;
import com.ruan.query.CommentsQuery;
import com.ruan.vo.CommentsVo;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName:CommentsService
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/7/4 12:12
 **/
@Service
public class CommentsService {

    @Autowired
    private CommentsMapper commentsMapper;

    @Autowired
    private CommentsTypeMapper commentsTypeMapper;
    public Result addComments(Comments comments) {
        int row = commentsMapper.addComments(comments);
        if(row != 1){
            return new Result(100,"评论发布失败");
        }else {
            return new Result(200,"评论发布成功");
        }
    }

    public List<CommentsVo> getCommentsList(CommentsQuery commentsQuery) {
        List<CommentsVo> commentsVoList = commentsMapper.getCommentsList(commentsQuery);
        for (CommentsVo i:commentsVoList){
            i.setCommentsType(commentsTypeMapper.getCommentsTypeById(i.getCommentsTypeId()));
        }
        return commentsVoList;
    }

    public Result deleteComments(Integer id) {
        int row = commentsMapper.deleteComments(id);
        if(row != 1){
            return new Result(100,"删除失败");
        }else {
            return new Result(200,"删除成功");
        }
    }

    public Result deleteCommentsByIds(Integer[] ids) {
        int row = commentsMapper.deleteCommentsByIds(ids);
        if(row != ids.length){
            return new Result(100,"删除失败");
        }else {
            return new Result(200,"删除成功");
        }
    }
}
